package com.liu.common.exception;

import com.liu.common.bean.ResultBean;
import com.liu.common.controller.BaseController;
import org.apache.tomcat.util.http.fileupload.impl.FileSizeLimitExceededException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

import javax.naming.SizeLimitExceededException;

@RestControllerAdvice
public class GlobalExceptionHandler extends BaseController {



    @ExceptionHandler(Exception.class)
    public ResultBean handleException(Exception e) {
        e.printStackTrace();
        return fail("接口请求异常");
    }

    @ExceptionHandler(ValidateException.class)
    public ResultBean handleValidateException(ValidateException e) {
        return fail("验证错误",e.getError());
    }


    @ExceptionHandler(FileSizeLimitException.class)
    public ResultBean handlerFileSizeLimitException(FileSizeLimitException e) {
        return fail(e.getMessage());
    }

    @ExceptionHandler(FileNotExistException.class)
    public ResultBean handlerFileNotExistException(FileNotExistException e) {
        return fail(e.getMessage());
    }

    @ExceptionHandler({MaxUploadSizeExceededException.class, SizeLimitExceededException.class, FileSizeLimitExceededException.class})
    public ResultBean handlerUploadException(Exception e){
        return fail("文件大小超出限制");
    }




}
